<template>
    <el-dialog v-dialogDrag :title="!dataForm.id ? '新增' : '修改'" :close-on-click-modal="false"
        :visible.sync="visible" @close="handleClose" :center="true">
        <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
            label-width="80px">
            <el-form-item label="名称">
                <el-input v-model="dataForm.name" placeholder="名称"  clearable></el-input>
            </el-form-item>
            <el-form-item label="类型" >
             <el-input v-model="dataForm.type" placeholder="请输入类型"  clearable></el-input>
            </el-form-item>
            <el-form-item label="金额" >
               <el-input v-model="dataForm.money" placeholder="请输入金额" 
                 oninput="value=value.replace(/^\.+|[^\d.]/g,'')" clearable></el-input>
            </el-form-item>
            <el-form-item label="范围" >
               <el-input v-model="dataForm.range" placeholder="请输入范围"  clearable></el-input>
            </el-form-item>
            <el-form-item label="要求" >
               <el-input :rows="10" type="textarea" v-model="dataForm.require" placeholder="请输入要求"  clearable></el-input>
            </el-form-item>
           
        </el-form>
        <span slot="footer" class="dialog-footer">
            <el-button @click="visible = false">取消</el-button>
            <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
        </span>
    </el-dialog>
</template>
<script>
    import API from '@/api';
    import cloneDeep from 'lodash/cloneDeep';
    export default {
        data() {
            return {
                typeOptions: [],
                visible: false,
                dataForm: {
                    title: '',
                    totalArea: '',
                    address: '',
                    type: '',
                    deadline: ''
                },
                visible: false,
                dialogType: 1
            };
        },
        methods: {
            handleClose() {
                this.dataForm = {
                    title: '',
                    totalArea: '',
                    address: '',
                    type: '',
                    deadline: ''
                };
                this.$refs['dataForm'].resetFields();
            },
            init(item, type, appId) {
                console.log(type,item);
                this.visible = true;
                this.dialogType = type;
                if (item && type == 2) {
                    this.dataForm = item;
                }
            },

            // 表单提交
            dataFormSubmit() {
                console.log(this.dataForm.users);
                this.$refs['dataForm'].validate((valid) => {
                    if (valid) {

                        let params = cloneDeep(this.dataForm);
                        var tick = this.dialogType == 1 ? API.iaInvestorder.addiaInvestOrder(params) : API.iaInvestorder.editiaInvestOrder(params);
                        tick.then((data) => {
                            if (data.code == '0000') {
                                this.$message({
                                    message: `${this.dialogType == 2 ? '修改成功' : '新增成功'}`,
                                    type: 'success',
                                    duration: 1500,
                                    onClose: () => {
                                        this.visible = false;
                                        this.$emit('refreshDataList');
                                    }
                                });
                            }
                        });
                    }
                });
            }
        }
    };
</script>